data = load('ex1data1.txt'); 
x = data(:,1);
y = data(:,2);
figure;
plot(x,y,'r*','MarkerSize',10);
xlabel('Profit in $ 10,100s');
ylabel('Population of city in $ 10,100s');

m = length(y);
x = [ones(m,1),data(:,1)];
theta = zeros(2,1);
iterations = 1500;
alpha = 0.01;
j = zeros(m,1);

for iter = 1:iterations
	j = x*theta - y;
	temp1 = theta(1) - alpha * (1/m) * sum(j .*x(:,1));
	temp2 = theta(2) - alpha * (1/m) * sum(j .*x(:,2));
	theta(1) = temp1;
	theta(2) = temp2;
	%computeCost(x,y,theta);
	j = 0;
	j = x*theta - y;
	j = (1/(2*m)) * sum(j.*j);
end

